package com.mzw.mzw_gateway.filter;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.google.common.util.concurrent.RateLimiter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author L1nAn
 * 测试网关限流
 */
@Component
@Slf4j
public class helloWorld {
    @Resource
    private RateLimiter rateLimiter;
    public  void test() {
        //限流过滤
        if (!rateLimiter.tryAcquire()) {
            log.error("请求太频繁了，被限流了!!!");
            throw new RuntimeException();
        }
        System.out.println("你好");
    }
}
